package com.liu.security.controller;

import com.liu.efk.domain.ResultVo;
import com.liu.security.pojo.DUser;
import com.liu.security.service.DUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.Authentication;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.security.crypto.password.PasswordEncoder;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.security.Principal;

/**
 * Created by shi860715@126.com
 * Date 2021/8/12 14:35
 * 获取当前登录用户
 */
@RestController
@CrossOrigin
public class DUserController {

    @Autowired
    DUserService dUserService;


    @GetMapping("/system/user")
    public ResultVo getList(){

        return  ResultVo.success(dUserService.list());

    }



    @PostMapping("/system/user")
    public ResultVo addUser(@RequestBody DUser user){
         boolean flag = dUserService.add(user);
         if(flag){
             return ResultVo.success("用户添加成功！");
         }else {
             return ResultVo.faild("用户添加失败！");
         }


    }

    @GetMapping("/system/user/roles/{id}")
    public ResultVo getUserRoles(@PathVariable("id") Integer id){
        return ResultVo.success(dUserService.getDuserRoles(id));

    }

    @GetMapping("/system/user/permission/{id}")
    public ResultVo getUserPermission(@PathVariable("id") Integer id){
        return ResultVo.success(dUserService.getUserPermission(id));

    }






}
